package com.shanyi.sendmsg.controller;

import com.shanyi.sendmsg.tool.IPTool;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/ip")
public class GetIPAddrController {
    
    @Resource
    private IPTool ipTool;
    
    @GetMapping("/test")
    public String getIPAddr() throws Exception {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

        return IPTool.getIP(attributes.getRequest());
    }
}
